package com.ingrid.javi.model;

import android.widget.EditText;

public class ValueInRangeValidator extends EditTextValidator {

	private int minValue;
	private int maxValue;

	public ValueInRangeValidator(EditText editText, int minValue, int maxValue) {
		super(editText);
		this.minValue = minValue;
		this.maxValue = maxValue;
	}

	@Override
	public boolean isValid() {
		String strValue = this.editText.getText().toString();
		if (strValue.isEmpty()) {
			return false;
		}

		int value = Integer.parseInt(strValue);

		return value >= this.minValue && value <= this.maxValue;
	}

	public boolean isValidSingleReturn() {
		boolean isValid;

		String strValue = this.editText.getText().toString();
		if (strValue.isEmpty()) {
			isValid = false;
		} else {
			int value = Integer.parseInt(strValue);

			isValid = value >= this.minValue && value <= this.maxValue;
		}

		return isValid;
	}

}
